package com.jakewharton.rxbinding4.component;

import static com.jakewharton.rxbinding4.internal.Preconditions.checkNotNull;

import com.jakewharton.rxbinding4.InitialValueObservable;

import io.reactivex.rxjava3.annotations.CheckReturnValue;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.functions.Consumer;
import ohos.agp.components.Slider;

/**
 * Static factory methods for creating {@linkplain Observable observables} and {@linkplain Consumer
 * actions}* for {@link Slider}.
 */
public final class RxSlider {
    /**
     * Create an observable of progress value changes on {@code view}.
     * <p>
     * <em>Warning:</em> The created observable keeps a strong reference to {@code view}. Unsubscribe
     * to free this reference.
     * <p>
     * <em>Note:</em> A value will be emitted immediately on subscribe.
     *
     * @param view view
     * @return the initial value observable
     */
    @CheckReturnValue
    @NonNull
    public static InitialValueObservable<Integer> changes(@NonNull Slider view) {
        checkNotNull(view, "view == null");
        return new SeekBarUpdateObservable(view, null);
    }

    /**
     * Create an observable of progress value changes on {@code view} that were made only from the
     * user.
     * <p>
     * <em>Warning:</em> The created observable keeps a strong reference to {@code view}. Unsubscribe
     * to free this reference.
     * <p>
     * <em>Note:</em> A value will be emitted immediately on subscribe.
     *
     * @param view view
     * @return the initial value observable
     */
    @CheckReturnValue
    @NonNull
    public static InitialValueObservable<Integer> userChanges(@NonNull Slider view) {
        checkNotNull(view, "view == null");
        return new SeekBarUpdateObservable(view, true);
    }

    /**
     * Create an observable of progress value changes on {@code view} that were made only from the
     * system.
     * <p>
     * <em>Warning:</em> The created observable keeps a strong reference to {@code view}. Unsubscribe
     * to free this reference.
     * <p>
     * <em>Note:</em> A value will be emitted immediately on subscribe.
     *
     * @param view view
     * @return the initial value observable
     */
    @CheckReturnValue
    @NonNull
    public static InitialValueObservable<Integer> systemChanges(@NonNull Slider view) {
        checkNotNull(view, "view == null");
        return new SeekBarUpdateObservable(view, false);
    }

    /**
     * Create an observable of progress change events for {@code view}.
     * <p>
     * <em>Warning:</em> The created observable keeps a strong reference to {@code view}. Unsubscribe
     * to free this reference.
     * <p>
     * <em>Note:</em> A value will be emitted immediately on subscribe.
     *
     * @param view view
     * @return the initial value observable
     */
    @CheckReturnValue
    @NonNull
    public static InitialValueObservable<SeekBarChangeEvent> changeEvents(@NonNull Slider view) {
        checkNotNull(view, "view == null");
        return new SeekBarChangeEventObservable(view);
    }

    private RxSlider() {
        throw new AssertionError("No instances.");
    }
}
